package org.zqy.util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistryBuilder;

/**
 * 在使用Hibernate开发项目时，一定要保证只有一个sessionfactory 一个数据库对应一个sessionfactory
 * 
 * @author zqy
 * 
 */
final public class MySessionFactory {
	private static SessionFactory sf = null;
	static {
		Configuration cfg = new Configuration().configure();
		ServiceRegistryBuilder serviceRegistry = new ServiceRegistryBuilder()
				.applySettings(cfg.getProperties());
		sf = cfg.buildSessionFactory(serviceRegistry.buildServiceRegistry());
	}

	public static SessionFactory getSessionFactory() {
		return sf;
	}

	private MySessionFactory() {

	}
}
